//class Solution {
//    public boolean isPerfectSquare(int num) {
////        if (num == 0 || num == 1) return true;
//
//        long left = 0, right = num/2 + 1, mid;
//        while (left <= right){
//            mid = left + (right - left)/2;
//            if (mid*mid == num) return true;
//            if (mid*mid < num) left = mid+1;
//            if (mid*mid > num) right = mid-1;
//        }
//        return false;
//    }
//}



//二刷
class Solution {
    public boolean isPerfectSquare(int num) {
        long l = 1, r = num/2+1;
        //[ , ]
        while (l <= r){
            long mid = (l+r)/2;
            long m = mid*mid;
            if(m == num) return true;
            else if(m < num) l = mid+1;
            else r = mid-1;
        }
        return false;

    }
}